//
//  optionView.m
//  GaKan
//
//  Created by mac on 17/9/7.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "optionView.h"

@implementation optionView
//全局变量
{
    UILabel *name;
    UILabel *lastdate;
    UIButton *login;
}
@synthesize blueView,whiteView,alphaiView;
//重写init函数
-(instancetype)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if (self) {
        blueView=[[UIView alloc]initWithFrame:CGRectMake(0, 20, SCREENWIDTH*0.5, (SCREENHEIGHT-20)/3)];
        blueView.backgroundColor=COLOR(13, 153, 255, 1.0);
        [self addSubview:blueView];
        UIImageView *head=[[UIImageView alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(blueView.frame)/3, 60, 60)];
        head.image=[UIImage imageNamed:@"11"];
        [blueView addSubview:head];
        name=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(head.frame)+10, CGRectGetMinY(head.frame)+15, 100, 30)];
        lastdate=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(head.frame)+5, CGRectGetMaxY(name.frame), 200, 30)];
        login=[[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(head.frame)+10, CGRectGetMinY(head.frame)+15, 100, 30)];
            [login setTitle:@"点击登录" forState:UIControlStateNormal];
            login.titleLabel.font = [UIFont systemFontOfSize: 15.0];
            login.layer.cornerRadius = 8.0;
            login.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
            [login setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [login addTarget:self action:@selector(BTNlogin) forControlEvents:UIControlEventTouchDown];
        
        whiteView=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(blueView.frame), CGRectGetMaxX(blueView.frame), (SCREENHEIGHT-20)*2/3)];
        whiteView.backgroundColor=[UIColor whiteColor];
        [self addSubview:whiteView];
        
        
        
        alphaiView=[[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(blueView.frame), CGRectGetMinY(blueView.frame), SCREENWIDTH-CGRectGetMaxX(blueView.frame), SCREENHEIGHT-20)];
        alphaiView.backgroundColor=[UIColor clearColor];
        [self addSubview:alphaiView];

        [self UIInit];
    }
    return self;
}
//UI设定
-(void)UIInit{
            
        
        
        if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"is_login"] isEqualToString:@"1"]) {
            [login removeFromSuperview];
            
            name.text=[[NSUserDefaults standardUserDefaults] objectForKey:@"user_name"];
            name.font=[UIFont systemFontOfSize:17];
            name.textAlignment=NSTextAlignmentLeft;
            name.textColor=[UIColor blackColor];
            [blueView addSubview:name];
            
            
            lastdate.text=[NSString stringWithFormat:@"VIP:%@到期",[[NSUserDefaults standardUserDefaults] objectForKey:@"exp"]];
            lastdate.font=[UIFont systemFontOfSize:13];
            lastdate.textAlignment=NSTextAlignmentLeft;
            lastdate.textColor=[UIColor whiteColor];
            //[blueView addSubview:lastdate];
            
        } else {
            [name removeFromSuperview];
            [lastdate removeFromSuperview];
            
            [blueView addSubview:login];
        }
        
        
                //NSLog(@"++++++++++++++++++++++++");
}
//协议事件
-(void)BTNlogin{
    [_delegate logInOfdelegater];
}

@end













